import { makeAutoObservable, runInAction } from 'mobx'
import { getManageInfo } from '@/pages/report/department/api'
import { setLocalStorage } from '@/storage'
import type { ManageType } from '@/pages/report/department/interface'
import { history } from 'umi'

class Store {
    dataSource: Partial<ManageType> = {}
    constructor() {
        makeAutoObservable(this)
        this.fetchManageInfo()
    }

    /** 培训讲师数据 */
    async fetchManageInfo() {
        const { data } = await getManageInfo()
        runInAction(() => {
            this.dataSource = data
            setLocalStorage('TRAINER_REPORT_DATA', data)
            if (JSON.stringify(data) === '{}') {
                history.replace({ pathname: '/report/nodata', query: { type: 'trainer' } })
            }
        })
    }
}

export default Store
